document.addEventListener("DOMContentLoaded", function () {
    var page = document.getElementsByClassName("pagination")[0];
    var pageNum = makeArray(page.getElementsByTagName("li"));
    var pre = pageNum.shift();
    var next = pageNum.pop();
    var current = 0;

//    next.onclick = function () {
//        pre.className = "";
//        
//        document.getElementById("tow").innerHTML= "<span aria-hidden=\"true\"> « </span>";
//        console.log(current, pageNum.length);
//        if (current == pageNum.length - 1) {
//            return;
//        }
//        for (var i = 0; i < pageNum.length; i++) {
//            pageNum[i].className = "";
//        }
//        pageNum[current + 1].className = "active";
//        if (current == pageNum.length - 2) {
//            next.className = "disabled";
//            next.innerHTML = "<span><span aria-hidden = \"true\" > » </span></span>";
//        }
//        current++
//    }
//    pre.onclick = function () {
//        next.className = "";
//        next.innerHTML = "<a href=\"#\" aria-label=\"Previous\"><span aria-hidden=\"true\"> » </span></a>";
//        console.log(current, pageNum.length);
//        if (current == 0) {
//            return;
//        }
//        for (var i = 0; i < pageNum.length; i++) {
//            pageNum[i].className = "";
//        }
//        pageNum[current - 1].className = "active";
//        if (current == 1) {
//            pre.className = "disabled";
//            pre.innerHTML = "<span><span aria-hidden = \"true\" > « </span></span>";
//        }
//        current--;
//    }

       current=document.getElementById("pageNow").value;
       current--;
            if (current == 0) {
                pre.className = "disabled";
                next.className = "";
            } else if (current == pageNum.length - 1) {
                next.className = "disabled";
               
                pre.className = "";
               
            } else {
                pre.className = "";
          
                next.className = "";
               
            }
            console.log(current);
            for (var i = 0; i < pageNum.length; i++) {
                pageNum[i].className = "";
            }
            pageNum[current].className = "active";
});

var makeArray = function (obj) {
    return Array.prototype.slice.call(obj, 0);
}
try {
    Array.prototype.slice.call(document.documentElement.childNodes, 0)[0].nodeType;
} catch (e) {
    makeArray = function (obj) {
        var res = [];
        for (var i = 0, len = obj.length; i < len; i++) {
            res.push(obj[i]);
        }
        return res;
    }
}